package com.yanqu.road.server.cmd.wingroom.watchplayer;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.wingroom.WingRoomMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @author ：zfr
 * @date ：2022/2/23 10:12
 */
@Cmd(code = GameProtocol.S_WING_ROOM_WATCH_OTHER_PLAYER, desc = "拜访其他玩家厢房")
public class WatchOtherPlayerWingRoomCmd extends AbstractCommand {
    private long otherPlayerServerId;
    private long otherPlayerUserId;
    private WingRoomProto.WatchOtherPlayerReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = WingRoomProto.WatchOtherPlayerReqMsg.parseFrom(packet.getBytes());
        otherPlayerServerId = reqMsg.getOtherPlayerServerId();
        otherPlayerUserId = reqMsg.getOtherPlayerUserId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (otherPlayerServerId == GameServer.getInstance().getServerId()) {
            //本服拜访
            WingRoomProto.WatchOtherPlayerRespMsg.Builder respMsg;
            respMsg = WingRoomMgr.getVisitMsg(otherPlayerUserId);
            player.sendPacket(Protocol.U_WING_ROOM_WATCH_OTHER_PLAYER, respMsg);
        } else {
            //跨服
            player.sendPacket(CrossProtocol.C_WING_ROOM_VISIT_OTHER_PLAYER, reqMsg.toBuilder());
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
